package com.kly.user.task.v2;

import cn.hutool.core.net.NetUtil;
import com.alibaba.nacos.api.config.annotation.NacosValue;
import com.fqgj.log.factory.LogFactory;
import com.fqgj.log.interfaces.Log;
import com.kly.user.db.dao.UserDao;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;

/**
 * 修复用户注册时间
 */
@Service
public class RepairRegisterTask {

    private static Log logger = LogFactory.getLog(RepairRegisterTask.class);

    @NacosValue(value = "${task.job.executor.ip}", autoRefreshed = true)
    private String taskJobExecutor;
    @NacosValue(value = "${enable.repair.register.switch:true}", autoRefreshed = true)
    private Boolean enableRepairRegisterSwitch;
    private String localIP = NetUtil.getLocalhostStr();
    @Resource
    UserDao userDao;

    /**
     * 执行频率：10分钟
     */
    @Scheduled(fixedDelay = 1000 * 600)
    public void run() {
        logger.info("====RepairRegisterTask start");
        if (!taskJobExecutor.contains(localIP)) {
            logger.info("=============RepairRegisterTask, currentLocalAddress:{}, onlyExecuteTaskIn:{}", localIP, taskJobExecutor);
            return;
        }
        if (!enableRepairRegisterSwitch) {
            logger.info("=============RepairRegisterTask, enableFlashchatSwitch:{}", enableRepairRegisterSwitch);
            return;
        }

        userDao.repairRegisterDateIfRegisterIsNull();

    }


}